<?php
/**
 * Created by PhpStorm.
 * User: hui
 * Date: 16/8/5
 * Time: 10:57
 */
namespace app\index\model;

use think\Model;
use think\Session;

class Msg extends Model
{
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = true;
    // 关闭自动写入update_time字段
    protected $updateTime = false;
    // 定义时间戳字段名
    protected $createTime = 'sendtime';
    // 设置当前模型的数据库连接
    protected $connection = 'db_config1';
    protected $table = 'w_msg';

    protected $insert = ['status' => 1];

    public function new_msg()
    {
        $this->data([
            'admin_id' => '1',
            'uuid'     => Session::get('uuid'),
            'title'    => 'hello',
            'content'  => 'hello world',
            'status'   => 1,
        ]);
        return $res = $this->save();
    }

    public function get_msg($status)
    {
        $uuid = new Find();
        $uuid = $uuid->get_uuid();
        $msg = self::where('uuid', $uuid)
            ->where('status', $status)
            ->order('sendtime', 'desc')
            ->paginate(15);
        if (count($msg) < 1) {
            return false;
        } else {
            return $msg;
        }
    }
}